﻿@model DHQGHN.PM2.Models.Online.Khaisinh4Model
           <style>
    .ui-tooltip, .arrow:after {
        background: #FAFAD2;
    }

    .ui-tooltip {
        color: black;
        font-size: 12px;
    }

    .arrow {
        width: 70px;
        height: 16px;
        overflow: hidden;
        position: absolute;
        left: 50%;
        margin-left: -35px;
        bottom: -16px;
    }

        .arrow.top {
            top: -16px;
            bottom: auto;
        }

        .arrow.left {
            left: 20%;
        }

        .arrow:after {
            content: "";
            position: absolute;
            left: 20px;
            top: -20px;
            width: 25px;
            height: 25px;
            box-shadow: 6px 5px 9px -9px black;
            -webkit-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            transform: rotate(45deg);
        }

        .arrow.top:after {
            bottom: -20px;
            top: auto;
        }
</style>
<script>
    @functions{
        public string GetAntiForgeryToken()
        {
            string cookieToken, formToken;
            AntiForgery.GetTokens(null, out cookieToken, out formToken);
            return cookieToken + "," + formToken;
        }
    };
    $('.mnResident #mainForm').setMask("Đang thực hiện...");
    jQuery(function ($) {
        Tooltip();
        var dem = 0;
        var total = 3;
        Checkngay("DAYKS4");
        Checkthang("MONTHKS4");
        Checknam("YEARKS4");
        Checkcmnd("LR_IDCARD_NUM");
        codedob = $("#CODEDOB").val();
        tinhdob = $("#CODEDOB").val().substring(0, 2);
        huyennpdob = $("#CODEDOB").val().substring(0, 5);
        if (codedob != "") {
            $("#TINHKS4").val(tinhdob);
            total++;
        }
        if ($("#TINHKS4").val() != "-1") {
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS4").val(),
                    level: '2'
                },
                success: function (states) {
                    $("#HUYENKS4").append('<option value="' + '-1' + '">' +
                '-- Chọn Huyện --' + '</option>');
                    $.each(states, function (i, state) {
                        $("#HUYENKS4").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function () {
                    $("#HUYENKS4").val(huyennpdob);
                    $("#XAKS4").empty();
                    $("#XAKS4").append('<option value="' + '-1' + '">' +
                        '-- Chọn Xã --' + '</option>');
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("GetAdministrativeUnit1")',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        dataType: 'json',

                        data: {
                            code: $("#HUYENKS4").val(),
                            level: '3'
                        },

                        success: function (states) {

                            $.each(states, function (i, state) {
                                $("#XAKS4").append('<option value="' + state.Value + '">' +
                                    state.Text + '</option>');

                            });

                        },
                        complete: function () {
                            $("#XAKS4").val(codedob);
                            dem++;
                            checkloading(dem, total);
                        },
                        error: function (ex) {
                            alert('Failed to retrieve states.' + ex);
                        }
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
        } else {
            $("#HUYENKS4").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XAKS4").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
        }
        $("#TINHKS4").change(function () {
            
            $("#HUYENKS4").empty();
            $("#XAKS4").empty();
            $("#HUYENKS4").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XAKS4").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS4").val(),
                    level: '2'
                },
                success: function (states) {
                    $.each(states, function (i, state) {
                        $("#HUYENKS4").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function (states) {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        })
        $("#HUYENKS4").change(function () {
            $("#XAKS4").empty();
            $("#XAKS4").append('<option value="' + '-1' + '">' +
                '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")', // we are calling json method
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#HUYENKS4").val(),
                    level: '3'
                },

                success: function (states) {

                    $.each(states, function (i, state) {
                        $("#XAKS4").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function () {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'COUNTRY' },
            success: function (data, textStatus, jqXHR) {
                $(".LR_COUNTRY_ID").append('<option value="">' +
               '-- Chọn Quốc tịch --' + '</option>');
                $.each(data, function (i, item) {
                    $(".LR_COUNTRY_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');
                });
                $(".LR_COUNTRY_ID").val("@Model.LR_COUNTRY_ID");
            },
            complete: function () {
                dem++;
                checkloading(dem, total);
            }

        });

        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'RELATION' },
            success: function (data, textStatus, jqXHR) {

                $.each(data, function (i, item) {
                    $(".LR_FAMILY_RELATION_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');

                });
                $(".LR_FAMILY_RELATION_ID").val(@Model.LR_FAMILY_RELATION_ID);
            },
            complete: function () {
                dem++;
                checkloading(dem, total);
            }
        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'ETHNIC' },
            success: function (data, textStatus, jqXHR) {
                $(".LR_ETHNIC_ID").append('<option value="">' +
            '-- Chọn Dân tộc --' + '</option>');
                $.each(data, function (i, item) {
                    $(".LR_ETHNIC_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');
                });
                $(".LR_ETHNIC_ID").val(@Model.LR_ETHNIC_ID);
            },
            complete: function () {
                dem++;
                checkloading(dem, total);
            }

        });
        function ClickButton(Next) {
            $("#divLoading").show();
            var ngay = $("#DAYKS4").val();
            var thang = $("#MONTHKS4").val();
            var nam = $("#YEARKS4").val();
            xa = $("#XAKS4").val();
            if (xa == "-1") {
                xa = "";
            }

            var dataSend = {
                'RESIDENT_ID': $('#selectMenu').val(),
                'LR_LNAME': $("#LR_LNAME").val(),
                'LR_MNAME': $("#LR_MNAME").val(),
                'LR_FNAME': $("#LR_FNAME").val(),
                'LR_DOB': nam + thang + ngay,
                'LR_ETHNIC_ID': $(".LR_ETHNIC_ID").val(),
                'LR_COUNTRY_ID': $(".LR_COUNTRY_ID").val(),
                'LR_RPOB_ADM_UNIT_ID': xa,
                'LR_IDCARD_NUM': $("#LR_IDCARD_NUM").val(),
                'LR_FAMILY_RELATION_ID': $(".LR_FAMILY_RELATION_ID").val(),
                'NEXT': Next,
            };
            var jqXHR = $.ajax({
                url: '@Url.Action("Khaisinh4New","Online")',
                dataType: 'html',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                method: 'post',
                data: dataSend,
                cache: false,
                success: function myfunctionSuccess(data, textStatus, jqXHR) {
                    if (Next != '2') {
                        $('.mnResident #mainForm').unMask();
                        $('#mainForm').html(data);
                    } else {
                        window.location.href = '@Url.Action("Login","Online")';
                    }
                },
                complete: function (jqXHR, textStatus) {
                    if (Next == '1') {
                        $('#thongtin').text("THÔNG TIN TÌNH TRẠNG HÔN NHÂN");
                    } else {
                        $('#thongtin').text("THÔNG TIN MẸ ĐẺ");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('Có lỗi xảy ra trong quá trình lưu thông tin: ' + errorThrown);
                },

            });
        }
        $("#btnNext").click(function (event, giatri) {
            if (checkhtml()) {
                alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
            } else {
                if (giatri != null) {
                    ClickButton(giatri);
                }
                else {
                    if (Checkdatetime("DAYKS4", "MONTHKS4", "YEARKS4") == 0) {
                        $('.mnResident #mainForm').setMask("Đang thực hiện...");
                        ClickButton(1);
                    }
                }
            }
        });
        $("#btnBack").click(function () {
            if (checkhtml()) {
                alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
            } else {
                $('.mnResident #mainForm').setMask("Đang thực hiện...");
                ClickButton(0);
            }
        });
    });
</script>

<div class="row margin-top-20">
    <div class="col-md-6">
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Họ</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.LR_LNAME, new { @class = "form-control ", MaxLength = 50, @placeholder = "Họ" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Tên đệm</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.LR_MNAME, new { @class = "form-control ", MaxLength = 150, @placeholder = "Tên đệm" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Tên khai sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.LR_FNAME, new { @class = "form-control ", MaxLength = 50, @placeholder = "Tên khai sinh" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Ngày sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.DAYKS4, new { @class = "form-control", style = "width: 25%; display: inline;padding-left: 4%;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.DAYKS4) })/@Html.TextBoxFor(model => model.MONTHKS4, new { @class = "form-control", style = "width: 25%; display: inline;padding-left: 1%;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.MONTHKS4)})/@Html.TextBoxFor(model => model.YEARKS4, new { @class = "form-control", style = "width: 40%; display: inline;padding-left: 1%;", MaxLength = 4, @title = @Html.ToolTipMessageFor(m => m.YEARKS4) })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Quan hệ với CH</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="LR_FAMILY_RELATION_ID form-control " ></select>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Số CMND/CCCD</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.LR_IDCARD_NUM, new { @class = "form-control ", MaxLength = 12, @title = @Html.ToolTipMessageFor(m => m.LR_IDCARD_NUM) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Quốc tịch</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="LR_COUNTRY_ID form-control"></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Dân tộc</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="LR_ETHNIC_ID form-control " ></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Nơi ĐK khai sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("TINHKS4", ViewData["DISTRICT_CODE"] as List<SelectListItem>, new { @class = "form-control ", @title = @Html.ToolTipMessageFor(m => m.TINH) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5"></label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("HUYENKS4", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.HUYEN) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5"></label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("XAKS4", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.XA) })
            </div>
        </div>
    </div>
    <div style="text-align:center; margin-top:30px;">
        <button class="btn btn-sm" id="btnBack" style="background-color: #2664B7; color:#ffffff; min-width:100px;"><i class="fa fa-angle-double-left"></i> Quay lại</button>
        <button class="btn btn-sm" id="btnNext" style="background-color: #2664B7; color:#ffffff; min-width:100px;">Tiếp tục <i class="fa fa-angle-double-right"></i></button>
    </div>
    <div>
        @Html.HiddenFor(model => model.CODEDOB)
        @Html.HiddenFor(model => model.LR_COUNTRY_ID)
        
    </div>
</div>




